<%= javascript_include_tag "sharing.js" %>
<%= javascript_include_tag 'link_adder.js'-%>

<% current_user_authorized_to_manage = Authorization.is_authorized?("manage", nil, @script, current_user) -%>


<ul class="buttons">
  <li><%= icon('script', script_path(@script), 'Return to Method', nil, 'Return to Method') -%></li>
  <li><%= icon('scripts', scripts_path, 'View all Methods', nil, 'View all Methods') -%></li>
</ul>

<h1>
	Editing Script: <%= link_to(h(@script.title), script_path(@script)) -%>
	<%= render :partial=>"layouts/sandbox_warning" %>
</h1>

<div class="show_basic">
  <% form_for @script, :html => {:multipart => true} do |f| %>
    <%= f.error_messages %>

    <center>
      <div style="width: 90%;">
	    <p>
          <b>File to upload:&nbsp;</b>
          <%= file_field :content, :data -%>
        </p>
		<p>(File is currently: <%= @script.original_filename %>)</p>

        <p style="margin-top: 1.5em;">
          <b>Title:</b><br/>
          <%= f.text_field :title, :style => "width: 100%;" -%>
        </p>

        <p style="margin-top: 0.5em;">
          <b>Description:</b><br/>
          <%= f.text_area :description, :style => "width: 100%;", :rows => 5 -%>
        </p>
		<div>
			<p>          
				<b>Link with Data Extracts:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "data_extracts", :resource_type => "Data Extracts",   # this is only for presentation, not for any processing
		      :collection=>@archives,:selected=>@selected_archives,:authorization_for_showing_already_done => false } -%>
		</p>
		</div>
			<br/>
			<div style="clear:both;">
				</div>
		<div>
			<p>
				<b>Link with Surveys:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "surveys", :resource_type => "Surveys",   # this is only for presentation, not for any processing
		      :collection=>@surveys,:selected=>@selected_surveys,:authorization_for_showing_already_done => true } -%>
		</p>
		</div>
		<br/>
		<div style="clear:both;">
			</div>
		<div>
			<p>          
				<b>Link with Scripts:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "scripts", :resource_type => "Scripts",   # this is only for presentation, not for any processing
		      :collection=>@scripts,:selected=>@selected_scripts,:authorization_for_showing_already_done => false } -%>
		</p>
		</div>
		<br/>
		<div style="clear:both;">
			</div>
		<div>
			<p>          
				<b>Link with Publications:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "publications", :resource_type => "Publications",   # this is only for presentation, not for any processing
		      :collection=>@publications,:selected=>@selected_publications,:authorization_for_showing_already_done => true } -%>
		</p>
		</div>

			<br/>
			<div style="clear:both;">
				</div>
		<p style="margin-top: 0.5em;">
	    	<b>Type:</b>
	<%= select_tag :method_type, options_for_select(method_type_options, @script.method_type)  %>
	</p>

        <%# only the owner should get to see this option (ability to reload defaults remain in 'edit' action, but project selector is disabled) -%>
        <% if current_user_authorized_to_manage -%>
          <%= render :partial => "assets/project_selector", :locals => { :resource_type => "Method",  # this is only for presentation, not for any processing
            :selected_project_id => @script.asset.project_id,
            :project_hash => current_user.generate_own_project_id_name_hash,
            :disable_project_select => true } -%>
        <% end -%>
      </div>

    <%# only the owner should be able to change sharing permissions -%>
    <% if current_user_authorized_to_manage -%>
      <p style="margin: 2.5em 0 0 0;">
          <%= render :partial => "assets/sharing_form", :locals => {:sharing_mode => @sharing_mode, :groups => @groups, :selected_groups => @selected_groups } -%>
      </p>

      <p style="margin: 0;">
        <%= render :partial => "assets/attribution_form", :locals => { :resource_type => "Method",  # this is only for presentation, not for any processing so you can change it safely if required
          :existing_attributions => Authorization.authorize_collection("show", @script.attributions_objects, current_user),
          :attribution_suggestions => Script.get_all_as_json(current_user) } -%>
      </p>
    <% end -%>

    <p style="text-align: center;">
      <%= f.submit "Update", :id => "script_submit_btn", :onclick => "javascript: validateScriptFields(false); return(false);"  -%> or <%= link_to "Cancel", script_path(@script) -%>
    </p>
  <% end %>
  </center>
</div>